package com.jungle.sp.daily.sms;

import cn.ucloud.common.config.Config;
import cn.ucloud.common.credential.Credential;
import cn.ucloud.common.exception.UCloudException;
import cn.ucloud.usms.client.USMSClient;
import cn.ucloud.usms.models.SendUSMSMessageRequest;
import cn.ucloud.usms.models.SendUSMSMessageResponse;
import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.Phonenumber;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static final String publicKey = "4eZCZmwro6y1rsDlnBywe11DHlxcpxZCo";
    public static final String privateKey = "8XWnORQvDn3488b7upjegoKfjq6NG49SwH4stb5Y44xj";
    public static final String projectId = "org-engsiw";
    public static final String templateId = "UTA241029V627C0";

    public static void main(String[] args) throws IOException {
        String swissNumberStr = "18949555420";
        PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
        try {
          Phonenumber.PhoneNumber swissNumberProto = phoneUtil.parse(swissNumberStr, "RC");
            System.out.println(swissNumberProto);
            boolean isValid = phoneUtil.isValidNumber(swissNumberProto);
            System.out.println(isValid);


            // PhoneNumberOfflineGeocoder geocoder = PhoneNumberOfflineGeocoder.getInstance();
            // // Outputs "Zurich"
            // System.out.println(geocoder.getDescriptionForNumber(swissNumberProto, Locale.ENGLISH));
            // // Outputs "Zürich"
            // System.out.println(geocoder.getDescriptionForNumber(swissNumberProto, Locale.GERMAN));
            // // Outputs "Zurigo"
            // System.out.println(geocoder.getDescriptionForNumber(swissNumberProto, Locale.ITALIAN));

            // System.out.println(phoneUtil.format(swissNumberProto, PhoneNumberUtil.PhoneNumberFormat.E164));
        } catch (NumberParseException e) {
            System.err.println("NumberParseException was thrown: " + e.toString());
        }

    }

    private static void start() {
        Config config = new Config();
        Credential credential = new Credential(
                publicKey,
                privateKey
        );

        SendUSMSMessageResponse resp;


        try (USMSClient client = new USMSClient(config, credential)) {
            sendSms1(client);
            // QueryUSMSTemplateRequest request = new QueryUSMSTemplateRequest();
            // request.setTemplateId(templateId);
            // request.setProjectId(projectId);
            // QueryUSMSTemplateResponse response = client.queryUSMSTemplate(request);
            // System.out.println("数据：=》"+JSON.toJSON(response));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void sendSms1(USMSClient client) throws UCloudException {
        SendUSMSMessageResponse resp;
        List<String> phoneNumbers = new ArrayList<>();
        phoneNumbers.add("(86)18949555420");
        // phoneNumbers.add("0091");

        SendUSMSMessageRequest req = new SendUSMSMessageRequest();
        req.setSigContent("...");
        req.setProjectId(projectId);
        req.setTemplateId(templateId);

        req.setPhoneNumbers(phoneNumbers);

        List<String> templateParams = new ArrayList<>();
        templateParams.add("424242");
        req.setTemplateParams(templateParams);

        resp = client.sendUSMSMessage(req);
        System.out.println("结果==>" + resp.toString());
    }
}

